<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/inc/taglibs.jsp"%>
<%@ page import="com.msmall.base.rms.util.RMSUtils" language="java"%>
<c:set var="AUTH_ACTION_ADD" value="<%=RMSUtils.AUTH_ACTION_ADD%>"></c:set>
<c:set var="AUTH_ACTION_REMOVE" value="<%=RMSUtils.AUTH_ACTION_REMOVE%>"></c:set>

<SCRIPT type="text/javascript">
$("#saveEntity").click(function(){
	$.ajax({
		cache: true,
		type: "POST",
		url: $('#entityForm').attr('action'),
		data:$('#entityForm').serialize(),
		async: false,
		error: function(error) {
		    alert("Connection error");
		},
		success: function(data) {
		    $("#main_main").html(data);
		}
	});
});

function authAdministerGroup(groupid){
	var administerid = ${"#administer_id"}.val();
	var action = '<c:out value="${AUTH_ACTION_REMOVE}"/>';
	if($("#ck_group_"+groupid).attr("checked")==true){
		action = '<c:out value="${AUTH_ACTION_ADD}"/>';
	}
	$.ajax({
		cache: true,
		type: "POST",
		url: siteServer + "/rms/administer/auth.do",
		data: 'administerid='+administerid + "&groupid=" + groupid + "&action="+action,
		dataType :'json',
		async: false,
		error: function(error) {
		    alert("Connection error");
		},
		success: function(data) {
		    if(data.code == 0){
		    }else{
		    	alert("授权失败").	
		    }
		}
	});
}
</SCRIPT>
<form id="entityForm" name="entityForm" action="<c:url value='/rms/administer/save.do'/>">
	<input type="hidden" id="administer_id" name="id" value="${entity.id}"/>
	<input type="hidden" id="i_groupids" name="groupids" value=""/>
	<table class="tableform" width="100%" cellspacing="0" cellpadding="0" border="0">
		<tbody>
		<tr>
			<td width="17%">
				用户名称：
				<font color="red">*</font>
			</td>
			<td width="83%">
				<div>
				<input id="username" class="w200" type="text" name="username" value="${entity.username}">
				<span class="error_msg" style="display: inline;"> </span>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<ul id="groupAuthTree" class="ztree"></ul>
			</td>
		</tr>
		<tr>
			<td colspan="2">
			<input id="saveEntity" class="btn Borange fw7 mb20" type="button" value="保   存">
			</td>
		</tr>
		</tbody>
	</table>
</form>
<br><br><br><br>
<ul>
<c:forEach var="aGroup" items="${allGroups}" varStatus="astatus">
	<li>
		<c:set var="authed" value="false"></c:set>
		<c:forEach var="bGroup" items="${authGroups }" varStatus="bstatus">
			<c:if test="${aGroup.id == bGroup.id }">
				<c:set var="authed" value="true"></c:set>
			</c:if>
		</c:forEach>
		<input type="checkbox" id="ck_group_${aGroup.id}" <c:if test="${authed}">checked="checked"</c:if>  onchange="javascript:authAdministerGroup(${aGroup.id})"/>
		<c:out value="${aGroup.groupName}"></c:out>
	</li>
</c:forEach>
</ul>
